<template>
	<view class="container">
		<h5 class="param-title detail-head">{{ paramTitle }}
			<u-button type="primary" class="research_btn" size="mini" shape="square"
				@click="isRead(index)">查询</u-button>
		</h5>
		<!-- 主控状态 -->
		<u-cell-group :border="false" v-if="type==0">
			<u-cell-item title="网络状态:" :arrow="false" :value="NETWORK[masterControl.param1] || masterControl.param1"
				:value-style="{color: comColor(masterControl.param1)}">
			</u-cell-item>
			<u-cell-item title="信号强度:" :arrow="false" :value="masterControl.param2">
			</u-cell-item>
			<u-cell-item title="主平台连接状态:" :arrow="false"
				:value="PLATFORM_CONNECT[masterControl.param3] || masterControl.param3"
				:value-style="{color: comColor(masterControl.param3)}">
			</u-cell-item>
			<u-cell-item title="运维平台连接状态:" :arrow="false"
				:value="PLATFORM_CONNECT[masterControl.param4] || masterControl.param4"
				:value-style="{color: comColor(masterControl.param4)}">
			</u-cell-item>
			<u-cell-item title="ICCID:" :arrow="false" :value="masterControl.param5">
			</u-cell-item>
			<u-cell-item title="整柜禁用状态:" :arrow="false" :value="IS_ENABLE[masterControl.param6] ||masterControl.param6"
				:value-style="{color: comColor2(masterControl.param6)}">
			</u-cell-item>
			<u-cell-item title="故障信息:" :arrow="false" :value="masterControl.param7">
			</u-cell-item>
		</u-cell-group>
		<!-- 仓状态 -->
		<view class="binparam" v-else-if="type == 1">
			<view class="bin_right">
				<view class="binone">
					<text class="labels">仓状态：</text>
					<text
						:style="{color: comColor(binStatus.param1)}">{{ CABIN_STATUS[binStatus.param1] ||  binStatus.param1}}</text>
				</view>
				<view class="binone">
					<text class="labels">充电电压：</text>
					<text>{{ binStatus.param2 }}V</text>
				</view>
				<view class="binone">
					<text class="labels">充电电流：</text>
					<text>{{ binStatus.param3 }}A</text>
				</view>
				<view class="binone">
					<text class="labels">有功功率：</text>
					<text>{{ binStatus.param4 }}W</text>
				</view>
				<view class="binone">
					<text class="labels">有功电能：</text>
					<text>{{ binStatus.param5 }}kW·h</text>
				</view>
				<view class="binone">
					<text class="labels">输出继电器状态：</text>
					<text
						:style="{color: comColor2(binStatus.param6)}">{{ RELAY_STATUS[binStatus.param6] || binStatus.param6 }}</text>
				</view>
				<view class="binone">
					<text class="labels">风机状态：</text>
					<text :style="{color: comColor(binStatus.param6)}" v-if="binStatus.param7 == 0">停止</text>
					<text v-else>{{binStatus.param7}}rpm</text>
				</view>
				<view class="binone">
					<text class="labels">加热部件状态：</text>
					<text
						:style="{color: comColor2(binStatus.param8)}">{{ HEAT1[binStatus.param8] ||  binStatus.param8}}</text>
				</view>
				<view class="binone">
					<text class="labels">实时温度：</text>
					<text>{{ binStatus.param9 }}℃</text>
				</view>
				<view class="binone">
					<text class="labels">仓门状态：</text>
					<text
						:style="{color: comColor2(binStatus.param10)}">{{ DOOR_STATUS[binStatus.param10] || binStatus.param10}}</text>
				</view>
				<view class="binone">
					<text class="labels">禁用状态：</text>
					<text
						:style="{color: comColor2(binStatus.param11)}">{{ IS_ENABLE[binStatus.param11] ||binStatus.param11}}</text>
				</view>

				<h5 class="label-title">故障信息</h5>
				<view class="binone">
					<text class="labels">输出过压：</text>
					<text
						:style="{color: comColor2(binStatus.param12)}">{{ IS_NORMAL[binStatus.param12] || binStatus.param12}}</text>
				</view>
				<view class="binone">
					<text class="labels">输出欠压：</text>
					<text
						:style="{color: comColor2(binStatus.param13)}">{{ IS_NORMAL[binStatus.param13] || binStatus.param13}}</text>
				</view>
				<view class="binone">
					<text class="labels">输出过流：</text>
					<text
						:style="{color: comColor2(binStatus.param14)}">{{ IS_NORMAL[binStatus.param14] || binStatus.param14}}</text>
				</view>
				<view class="binone">
					<text class="labels">仓低温：</text>
					<text
						:style="{color: comColor2(binStatus.param15)}">{{ IS_NORMAL[binStatus.param15] || binStatus.param15}}</text>
				</view>
				<view class="binone">
					<text class="labels">充电超时(充电时间大于最长充电时间)：</text>
					<text
						:style="{color: comColor2(binStatus.param16)}">{{ IS_NORMAL[binStatus.param16] || binStatus.param16}}</text>
				</view>
				<view class="binone">
					<text class="labels">非法开门：</text>
					<text
						:style="{color: comColor2(binStatus.param17)}">{{ IS_NORMAL[binStatus.param17] || binStatus.param17}}</text>
				</view>
				<view class="binone">
					<text class="labels">继电器状态异常(吸合不上或者断不开)：</text>
					<text
						:style="{color: comColor2(binStatus.param18)}">{{ IS_NORMAL[binStatus.param18] || binStatus.param18}}</text>
				</view>
				<view class="binone">
					<text class="labels">充电设备未正常连接(单位时间内检测到设备)：</text>
					<text
						:style="{color: comColor2(binStatus.param19)}">{{ IS_NORMAL[binStatus.param19] || binStatus.param19}}</text>
				</view>
				<view class="binone">
					<text class="labels">心跳超时(主控心跳超时)：</text>
					<text
						:style="{color: comColor2(binStatus.param20)}">{{ IS_NORMAL[binStatus.param20] || binStatus.param20}}</text>
				</view>
				<view class="binone">
					<text class="labels">仓过温：</text>
					<text
						:style="{color: comColor2(binStatus.param21)}">{{ IS_NORMAL[binStatus.param21] || binStatus.param21}}</text>
				</view>
				<view class="binone">
					<text class="labels">输出过载：</text>
					<text
						:style="{color: comColor2(binStatus.param22)}">{{ IS_NORMAL[binStatus.param22] || binStatus.param22}}</text>
				</view>
				<view class="binone">
					<text class="labels">暂停充电：</text>
					<text
						:style="{color: comColor2(binStatus.param23)}">{{ IS_NORMAL[binStatus.param23] || binStatus.param23}}</text>
				</view>
				<view class="binone">
					<text class="labels">仓门打开异常：</text>
					<text
						:style="{color: comColor2(binStatus.param24)}">{{ IS_NORMAL[binStatus.param24] || binStatus.param24}}</text>
				</view>
				<view class="binone">
					<text class="labels">消防启动：</text>
					<text
						:style="{color: comColor2(binStatus.param25)}">{{ IS_NORMAL[binStatus.param25] || binStatus.param25}}</text>
				</view>
			</view>
		</view>
		<!-- 检测单元状态信息 -->
		<u-cell-group :border="false" v-else-if="type == 2">
			<u-cell-item title="柜门状态：" :arrow="false"
				:value="`${CABIN_DOOR_STATUS[unitInfo.param1] || unitInfo.param1}`"
				:value-style="{color: comColor(unitInfo.param1)}">
			</u-cell-item>
			<u-cell-item title="供电状态：" :arrow="false"
				:value="`${POWER_SUPPLY_STATUS[unitInfo.param2] || unitInfo.param2}`"
				:value-style="{color: comColor(unitInfo.param2)}">
			</u-cell-item>
			<u-cell-item title="烟感状态：" :arrow="false" :value="`${SMOKE_DETECTOR[unitInfo.param3] ||unitInfo.param3}`"
				:value-style="{color: comColor2(unitInfo.param3)}">
			</u-cell-item>
			<u-cell-item title="环境温度：" :arrow="false" :value="`${unitInfo.param4}°C`">
			</u-cell-item>
			<u-cell-item title="水浸状态：" :arrow="false" :value="`${WATER_OUT[unitInfo.param5] || unitInfo.param5}`"
				:value-style="{color: comColor2(unitInfo.param3)}">
			</u-cell-item>
			<u-cell-item title="风扇状态：" :arrow="false" :value="`${IS_ENABLED[unitInfo.param6] || unitInfo.param6}`"
				:value-style="{color: comColor(unitInfo.param6)}">
			</u-cell-item>
			<u-cell-item title="电表有功电量：" :arrow="false" :value="`${unitInfo.param7}`">
			</u-cell-item>
			<u-cell-item title="电表电压：" :arrow="false" :value="`${unitInfo.param8}`">
			</u-cell-item>
			<u-cell-item title="电表电流：" :arrow="false" :value="`${unitInfo.param9}`">
			</u-cell-item>
			<u-cell-item title="电表有功功率：" :arrow="false" :value="`${unitInfo.param10}`">
			</u-cell-item>


			<h5 class="label-title warn-title">故障信息：</h5>
			<view class="warn-cell">
				<u-cell-item title="烟雾告警:" :arrow="false" :value="`${IS_NORMAL[unitInfo.param11] || unitInfo.param11}`"
					:value-style="{color: comColor2(unitInfo.param11)}">
				</u-cell-item>
				<u-cell-item title="消防告警:" :arrow="false" :value="`${IS_NORMAL[unitInfo.param12] || unitInfo.param12}`"
					:value-style="{color: comColor2(unitInfo.param12)}">
				</u-cell-item>
				<u-cell-item title="消防启动:" :arrow="false" :value="`${IS_NORMAL[unitInfo.param13] || unitInfo.param13}`"
					:value-style="{color: comColor2(unitInfo.param13)}">
				</u-cell-item>
				<u-cell-item title="水浸告警:" :arrow="false" :value="`${IS_NORMAL[unitInfo.param14] || unitInfo.param14}`"
					:value-style="{color: comColor2(unitInfo.param14)}">
				</u-cell-item>
				<u-cell-item title="防雷告警:" :arrow="false" :value="`${IS_NORMAL[unitInfo.param15] || unitInfo.param15}`"
					:value-style="{color: comColor2(unitInfo.param15)}">
				</u-cell-item>

				<u-cell-item title="漏保告警:" :arrow="false" :value="`${IS_NORMAL[unitInfo.param16] || unitInfo.param16}`"
					:value-style="{color: comColor2(unitInfo.param16)}">
				</u-cell-item>
				<u-cell-item title="风扇异常告警:" :arrow="false"
					:value="`${IS_NORMAL[unitInfo.param17] || unitInfo.param17}`"
					:value-style="{color: comColor2(unitInfo.param17)}">
				</u-cell-item>
				<u-cell-item title="异常断电告警:" :arrow="false"
					:value="`${IS_NORMAL[unitInfo.param18] || unitInfo.param18}`"
					:value-style="{color: comColor2(unitInfo.param18)}">
				</u-cell-item>
				<u-cell-item title="过流保护:" :arrow="false" :value="`${IS_NORMAL[unitInfo.param19] || unitInfo.param19}`"
					:value-style="{color: comColor2(unitInfo.param19)}">
				</u-cell-item>
				<u-cell-item title="输入过压告警:" :arrow="false"
					:value="`${IS_NORMAL[unitInfo.param20] || unitInfo.param20}`"
					:value-style="{color: comColor2(unitInfo.param20)}">
				</u-cell-item>
				<u-cell-item title="输入低压告警:" :arrow="false"
					:value="`${IS_NORMAL[unitInfo.param21] || unitInfo.param21}`"
					:value-style="{color: comColor2(unitInfo.param21)}">
				</u-cell-item>
				<u-cell-item title="消防电池欠压告警:" :arrow="false"
					:value="`${IS_NORMAL[unitInfo.param22] || unitInfo.param22}`"
					:value-style="{color: comColor2(unitInfo.param22)}">
				</u-cell-item>
				<u-cell-item title="电表通讯异常告警:" :arrow="false"
					:value="`${IS_NORMAL[unitInfo.param23] || unitInfo.param23}`"
					:value-style="{color: comColor2(unitInfo.param23)}">
				</u-cell-item>
				<u-cell-item title="系统过温告警:" :arrow="false"
					:value="`${IS_NORMAL[unitInfo.param24] || unitInfo.param24}`"
					:value-style="{color: comColor2(unitInfo.param24)}">
				</u-cell-item>
				<u-cell-item title="系统过载告警:" :arrow="false"
					:value="`${IS_NORMAL[unitInfo.param25] || unitInfo.param25}`"
					:value-style="{color: comColor2(unitInfo.param25)}">
				</u-cell-item>
			</view>
		</u-cell-group>
	</view>
</template>

<script>
	import state2js from './state2.js';
	import {
		getLockOption,
		batteryIsOn,

		NETWORK,
		PLATFORM_CONNECT,
		IS_ENABLE,
		IS_ONLINE,
		POWER_CHANGE,
		IS_WARN,
		IS_ENABLED,
		HEAT1,
		ABNORMAL_OUTAGE,
		FLOODLIGHT,
		MAINTAIN_DOOR,
		WATER_FEEDBACK,
		SMOKE_STATUS,
		IS_START,
		IS_FAULT,
		IS_NORMAL,
		OVETRCURRENT,
		IS_DORMANT,
		CURRENT_LIMIT,
		IS_AUTO,
		IS_FORBIDDEN,
		BATERRY_TYPE,
		RUN_STATUS,
		UNDERVOL,
		UPVOL,
		HIGHTEM,
		PRESSURE,
		MOS_STATUS,
		BMS_STATUS,
		IS_DOORS,
		IS_CHARGE,
		CHARGE_CURRENT,
		OVER_CURRENT,
		VOL_LOSE,
		NOTALLOW_CHARGE,
		BATTERY_ONLINE,
		LOAD_PROTECT,
		UP_VOL_PROTECT,
		CURRENT_LIMIT_WARN,
		CELL_HIGH_TEM,
		ENVIR_LOW_TEM,
		ENVIR_HIGH_TEM,
		MOS_HIGH_TEM,
		LOW_VOL_PROTECT,
		INVERSE_PROTECT,
		BMS_SIGN,
		MOS_PIPE_STATUS,
		BATTERY_ADJUST,
		BATTERY_STATUSING,
		BATTERY_CONTROL,
		DOOR_STATUS,
		BATTERY_ISON,
		DOOR_LOCK_SIGNAL,
		CABIN_STATUS,
		RELAY_STATUS,
		CABIN_DOOR_STATUS,
		POWER_SUPPLY_STATUS,
		SMOKE_DETECTOR,
		WATER_OUT,
	} from "@/common/config.js";
	export default {
		mixins: [state2js],
		data() {
			return {
				type: 0, //参数类型
				paramTitle: "", //参数模块名称
				binNum: 0, //仓个数
				currentIndex: null, //当前仓号
				command: null, //命令字
				deviceInfo: {}, //设备信息
				dgMessage: "", //检测状态提示信息
				index: null, //几号仓

				masterControl: {
					//主控状态
					param1: "",
					param2: "",
					param3: "",
					param4: "",
					param5: "",
					param6: "",
					param7: "",
				},
				unitInfo: {
					//检测单元状态信息
					param1: '',
					param2: '',
					param3: '',
					param4: '',
					param5: '',
					param6: '',
					param7: '',
					param8: '',
					param9: '',
					param10: '',
					param11: '',
					param12: '',
					param13: '',
					param14: '',
					param15: '',
					param16: '',
					param17: '',
					param18: '',
					param19: '',
					param20: '',
					param21: '',
					param22: '',
					param23: '',
					param24: '',
					param25: '',
				},

				binStatus: {
					param1: "",
					param2: "",
					param3: "",
					param4: "",
					param5: "",
					param6: "",
					param7: "",
					param8: "",
					param9: "",
					param10: "",
					param11: "",
					param12: "",
					param13: "",
					param14: "",
					param15: "",
					param16: "",
					param17: "",
					param18: "",
					param19: "",
					param20: "",
					param21: "",
					param22: "",
					param23: "",
					param24: "",
					param25: "",
				},

				NETWORK: NETWORK,
				PLATFORM_CONNECT: PLATFORM_CONNECT,
				IS_ENABLE: IS_ENABLE,
				IS_ONLINE: IS_ONLINE,
				POWER_CHANGE: POWER_CHANGE,
				IS_WARN: IS_WARN,
				IS_ENABLED: IS_ENABLED,
				HEAT1: HEAT1,
				ABNORMAL_OUTAGE: ABNORMAL_OUTAGE,
				FLOODLIGHT: FLOODLIGHT,
				MAINTAIN_DOOR: MAINTAIN_DOOR,
				WATER_FEEDBACK: WATER_FEEDBACK,
				SMOKE_STATUS: SMOKE_STATUS,
				IS_START: IS_START,
				IS_FAULT: IS_FAULT,
				IS_NORMAL: IS_NORMAL,
				OVETRCURRENT: OVETRCURRENT,
				IS_DORMANT: IS_DORMANT,
				CURRENT_LIMIT: CURRENT_LIMIT,
				IS_AUTO: IS_AUTO,
				IS_FORBIDDEN: IS_FORBIDDEN,
				BATERRY_TYPE: BATERRY_TYPE,
				RUN_STATUS: RUN_STATUS,
				UNDERVOL: UNDERVOL,
				UPVOL: UPVOL,
				HIGHTEM: HIGHTEM,
				PRESSURE: PRESSURE,
				MOS_STATUS: MOS_STATUS,
				BMS_STATUS: BMS_STATUS,
				IS_DOORS: IS_DOORS,
				IS_CHARGE: IS_CHARGE,
				CHARGE_CURRENT: CHARGE_CURRENT,
				OVER_CURRENT: OVER_CURRENT,
				VOL_LOSE: VOL_LOSE,
				NOTALLOW_CHARGE: NOTALLOW_CHARGE,
				BATTERY_ONLINE: BATTERY_ONLINE,
				LOAD_PROTECT: LOAD_PROTECT,
				UP_VOL_PROTECT: UP_VOL_PROTECT,
				CURRENT_LIMIT_WARN: CURRENT_LIMIT_WARN,
				CELL_HIGH_TEM: CELL_HIGH_TEM,
				ENVIR_LOW_TEM: ENVIR_LOW_TEM,
				ENVIR_HIGH_TEM: ENVIR_HIGH_TEM,
				MOS_HIGH_TEM: MOS_HIGH_TEM,
				LOW_VOL_PROTECT: LOW_VOL_PROTECT,
				INVERSE_PROTECT: INVERSE_PROTECT,
				BMS_SIGN: BMS_SIGN,
				MOS_PIPE_STATUS: MOS_PIPE_STATUS,
				BATTERY_ADJUST: BATTERY_ADJUST,
				BATTERY_STATUSING: BATTERY_STATUSING,
				BATTERY_CONTROL: BATTERY_CONTROL,
				DOOR_STATUS: DOOR_STATUS,
				BATTERY_ISON: BATTERY_ISON,
				DOOR_LOCK_SIGNAL: DOOR_LOCK_SIGNAL,
				CABIN_STATUS: CABIN_STATUS,
				RELAY_STATUS: RELAY_STATUS,
				CABIN_DOOR_STATUS: CABIN_DOOR_STATUS,
				POWER_SUPPLY_STATUS: POWER_SUPPLY_STATUS,
				SMOKE_DETECTOR: SMOKE_DETECTOR,
				WATER_OUT: WATER_OUT,

			}
		},
		computed: {
			// 柜控电源数量
			comCabinNum() {
				if (Number(this.binNum) < 16) {
					return 1;
				} else if (Number(this.binNum) >= 16 && Number(this.binNum) < 24) {
					return 2;
				} else {
					return 3;
				}
			},
			comColor() {
				return function(item) {
					if (item == 0) {
						return '#f56c6c';
					} else if (item == 1) {
						return '#19be6b'
					}
				}
			},
			comColor2() {
				return function(item) {
					if (item == 1) {
						return '#f56c6c';
					} else if (item == 0) {
						return '#19be6b'
					}
				}
			},
			detailYesOrNo() {
				return function(val) {
					if (val == 1) {
						return "是";
					} else if (val !== '' && val != 1) {
						return '否';
					} else {
						return '';
					}
				}
			},
		},
		onLoad(e) {
			this.deviceInfo = JSON.parse(decodeURIComponent(e.deviceInfo));
			this.type = e.type;
			this.binNum = e.binNum;
			this.index = Number(e.index);
			this.detailData();
			this.resetData();
			this.doRead(this.index);
		},
		methods: {
			resetData() {
				for (let key of Object.keys(this.masterControl)) {
					this.masterControl[key] = "";
				}
				for (let key of Object.keys(this.unitInfo)) {
					this.unitInfo[key] = "";
				}
				for (let key of Object.keys(this.binStatus)) {
					this.binStatus[key] = "";
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/static/css/common.scss";
	@import "../index.scss";

	.container {
		padding: 20rpx;

		.detail-head {
			position: relative;

			.research_btn {
				position: absolute;
				right: 0;
			}
		}
	}
</style>